package com.zcc.lesson02;

import com.zcc.lesson02.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class PreparedStatementTest {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement ps = null;

        try{
            con = JDBCUtils.getConnection();

            //预编译可以使用?占位符来代替参数
            String sql = "insert into users values(?,?,?,?,?)";
            ps=con.prepareStatement(sql);

            ps.setInt(1,5);
            ps.setString(2,"zww");
            ps.setString(3,"123456");
            ps.setString(4,"400820@qq.com");
            ps.setDate(5, new java.sql.Date(System.currentTimeMillis()));

            int i = ps.executeUpdate();

            if (i>0){
                System.out.println("插入成功！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JDBCUtils.release(con,ps,null);
        }
    }
}
